package com.hmdp.service.impl;

import com.hmdp.dto.Result;
import com.hmdp.entity.ShopType;
import com.hmdp.mapper.ShopTypeMapper;
import com.hmdp.service.IShopTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmdp.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.hmdp.utils.SystemConstants.SHOP_TYPE_LIST;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 虎哥
 * @since 2021-12-22
 */
@Service
public class ShopTypeServiceImpl extends ServiceImpl<ShopTypeMapper, ShopType> implements IShopTypeService {

    @Autowired
    RedisCache redisCache;
    @Override
    public Result queryTypeList() {
        //从Redis中查询shopTypeList
        List<ShopType> cacheList = redisCache.getCacheList(SHOP_TYPE_LIST);
        //不存在，则抛出异常
        if (cacheList.isEmpty()) {
            cacheList = getBaseMapper().selectList(null);
        }
        //存在直接返回
        return Result.ok(cacheList);
    }
}













